package com.datang.petstore.aop;/*
 * @auther 顶风少年
 * @mail dfsn19970313@foxmail.com
 * @date 2019-10-31 09:18
 * @notify
 * @version 1.0
 */

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.web.client.RestTemplate;

@Configuration
public class MailServer {

    public static void main(String[] args) {
        RestTemplate restTemplate = new RestTemplate();
        String forObject = restTemplate.getForObject("http://127.0.0.1:8080/demo/login?name=zhangsan&password=123",
                String.class);
        System.out.println(forObject);

        String forObject2 = restTemplate.getForObject("http://127.0.0.1:8080/demo/login?name=zhangsan&password=123",
                String.class);
        System.out.println(forObject2);
    }

    @Bean
    public JavaMailSenderImpl mailSender() {
        JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
        mailSender.setHost("smtp.163.com");//指定用来发送Email的邮件服务器主机名
        mailSender.setPort(25);//默认端口，标准的SMTP端口
        mailSender.setUsername("zmj15237497836@163.com");//此处的用户名就是你的邮箱账号
        mailSender.setPassword("Fmzbyy19970313");//就是刚刚设置的授权码
        return mailSender;
    }
}
//发送邮件
/*    @GetMapping("mail")
    public String sendMail() {//发送文本邮件
        SimpleMailMessage mailMessage = new SimpleMailMessage();
        mailMessage.setFrom("zmj15237497836@163.com");//你的邮箱账号,此处必须和连接对象中的邮箱账号一致
        mailMessage.setTo("asd974944918@qq.com");//发送给谁
        mailMessage.setSubject("spring发送邮件");//邮件主题
        mailMessage.setText("这是一封测试邮件");//邮件内容
        mailSender.send(mailMessage);
        return "ok";
    }

    @GetMapping("fjmail")
    public String sendMailfj() throws Exception{//发送带附件的邮件
        MimeMessage message = mailSender.createMimeMessage();
        MimeMessageHelper helper = new MimeMessageHelper(message,true);//true表明这个消息是multipart类型的
        helper.setFrom("zmj15237497836@163.com");//发件人
        helper.setTo("asd974944918@qq.com");//收件人
        helper.setSubject("spring发送邮件带图片");//主题
        helper.setText("这是一封测试邮件");//正文
        FileSystemResource resource = new FileSystemResource("C:\\Users\\dfsn1\\Pictures\\商品图片\\1.jpg");//此处我使用的本地的图片
        helper.addAttachment("一个图片.png", resource);//设置附件
        mailSender.send(message);
        return "ok";
    }*/
